﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Bot.Application.Dto;
using Bot.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Bot.WebAPI.Controllers
{
    [Route("api/v3/chatbot/sessions")]
    [ApiController]
    public class SessionsController : ControllerBase
    {

        private readonly IIntentAppService _intentAppService;
        public SessionsController(IIntentAppService intentAppService)
        {
            _intentAppService = intentAppService;
        }

        [HttpPost]
        [Route("{sessionId:Guid}:detectIntent")]
        public ActionResult<DetectIntentResponseDto> DetectIntent([FromRoute] Guid sessionId, [FromBody] DetectIntentRequestBodyDto detectIntentRequestBodyDto)
        {
            var detectIntentResponseDto = _intentAppService.DetectIntent(sessionId, detectIntentRequestBodyDto);
            return Ok(detectIntentResponseDto);
        }

        [HttpPost]
        [Route("{sessionId:Guid}:triggerAnIntent")]
        public ActionResult<TriggerAnIntentResponseDto> TriggerAnIntent([FromRoute] Guid sessionId, [FromBody] TriggerAnIntentRequestBodyDto triggerAnIntentRequestBodyDto)
        {
            var detectIntentResponseDto = _intentAppService.TriggerAnIntent(sessionId, triggerAnIntentRequestBodyDto);
            return Ok(detectIntentResponseDto);
        }

        [HttpPost]
        [Route("{sessionId:Guid}:submitForm")]
        public ActionResult<HighConfidenceAnswerDto> SubmitForm([FromRoute] Guid sessionId, [FromBody] SubmitFormRequestBodyDto submitFormRequestBodyDto)
        {
            var highConfidenceAnswerDto = _intentAppService.SubmitForm(sessionId, submitFormRequestBodyDto);
            return Ok(highConfidenceAnswerDto);
        }

        [HttpPost]
        [Route("{sessionId:Guid}:submitAuthentication")]
        public ActionResult<HighConfidenceAnswerDto> SubmitAuthentication([FromRoute] Guid sessionId, [FromBody] SubmitAuthenticationRequestBodyDto submitAuthenticationRequestBodyDto)
        {
            var highConfidenceAnswerDto = _intentAppService.SubmitAuthentication(sessionId, submitAuthenticationRequestBodyDto);
            return Ok(highConfidenceAnswerDto);
        }

        [HttpPost]
        [Route("{sessionId:Guid}:submitLocation")]
        public ActionResult<HighConfidenceAnswerDto> SubmitLocation([FromRoute] Guid sessionId, [FromBody] SubmitLocationRequestBodyDto submitLocationRequestBodyDto)
        {
            var highConfidenceAnswerDto = _intentAppService.SubmitLocation(sessionId, submitLocationRequestBodyDto);
            return Ok(highConfidenceAnswerDto);
        }

        [HttpPost]
        [Route("{sessionId:Guid}:rate")]
        public ActionResult<NotHelpfulAnswerDto> Rate([FromRoute] Guid sessionId, [FromBody] RateRequestBodyDto rateRequestBodyDto)
        {
            var notHelpfulAnswerDto = _intentAppService.Rate(sessionId, rateRequestBodyDto);

            return Ok(notHelpfulAnswerDto);
        }
    }
}
